/*
 *  clusterfusion.h
 *  bgsubtraction
 *
 *  Created by a1gucis on 4/20/09.
 *  Copyright 2009 __MyCompanyName__. All rights reserved.
 *
 */
#ifndef CLUSTER_FUSION_H
#define CLUSTER_FUSION_H
#define CLUST_NEIGHBOURHOOD 3

#include "systeminclude.h"
#include "clusters.h"
#include <iostream>

using namespace std;
class ClusterFusion {
private:
	IplImage *image; //1 channel labeled image
	int bgLabel;
	Clusters *tmpClusters;
	//forms the cluster of neighbourhood by neighbourhood matrix
	void formCluster(int row, int col, int neighbourhood, Clusters *clusters);
	
	//substitues the neighbourhood X neighbourhood matrix, starting at row, col with maxLabel
	void substituteCluster(int row, int col, int neighbourhood, int maxLabel);
	
	//****old technique
	//checks whether a cluster, starting at row, col has to be fused to its surrounding cluster marked as oldlabel.
	bool checkWhetherFusion(int row, int col, int oldLabel, int neighbourhood);

	//fuses the cluster at row, col, with the surrounding cluster marked as oldLabel
	void fuseCluster(int row, int col, int oldLabel);

public:
	ClusterFusion();
	~ClusterFusion();
	
	//fuses unnecessary clusters using image morphology techniques.
	void fuse(IplImage *image, int iterations);
	
	//scans the image for fusable clusters and fuses them if necessary. Background label and matrix neighbourhood is required as well.
	void fuse(IplImage *image, int bgLabel, int neighbourhood);
	
	
	//****old technique
	//scans the image for fusable clusters and fuses them if necessary. Background label is required as well.
	//void fuse(IplImage *image, int bgLabel);
	
	
	//debugging purposes
	void test();
};
#endif
